import { http } from "@/utils/http";

type Result = {
  success: boolean;
  data: Array<any>;
};
type ResultTable = {
  success: boolean;
  data?: {
    /** 列表数据 */
    list: Array<any>;
    /** 总条目数 */
    total?: number;
    /** 每页显示条目个数 */
    pageSize?: number;
    /** 当前页数 */
    currentPage?: number;
  };
};
//欢迎页数据
export const welcomeIndex = (data?: object,method?:'get') => {
  let path = getnewUrl("/home-statistics-index",data,method)
  return http.request<ResultTable>(method, path, { data });
};
export const welcomeIndex1 = (data?: object,method?:'get') => {
  let path = getnewUrl("/home-statistics-index1",data,method)
  return http.request<ResultTable>(method, path, { data });
};
//订单简报
export const welcomeOrder = (data?: object,method?:'get') => {
  let path = getnewUrl("/home-statistics-order",data,method)
  return http.request<ResultTable>(method, path, { data });
};
//开发简单简报
export const welcomePurchase = (data?: object,method?:'get') => {
  let path = getnewUrl("/home-statistics-purchase",data,method)
  return http.request<ResultTable>(method, path, { data });
};
//实物图片采集
export const welcomeCaiji = (data?: object,method?:'get') => {
  let path = getnewUrl("/home-statistics-caiji",data,method)
  return http.request<ResultTable>(method, path, { data });
};
//财务简报
export const welcomeCaiwu = (data?: object,method?:'get') => {
  let path = getnewUrl("/home-statistics-caiwu",data,method)
  return http.request<ResultTable>(method, path, { data });
};
export const welcomeQushi = (data?: object,method?:'get') => {
  let path = getnewUrl("/home-statistics-qushi",data,method)
  return http.request<ResultTable>(method, path, { data });
};
//客户分配统计
export const welcomeCustomerAssignment = (data?: object,method?:'get') => {
  let path = getnewUrl("/home-statistics-customer-assignment",data,method)
  return http.request<ResultTable>(method, path, { data });
};

export const welcomePendingCustomers = (data?: object,method?:'get') => {
  let path = getnewUrl("/home-statistics-pending-customers",data,method)
  return http.request<ResultTable>(method, path, { data });
};

//任务统计
export const welcomeTaskStatistics = (data?: object,method?:'get') => {
  let path = getnewUrl("/home-statistics-task",data,method)
  return http.request<ResultTable>(method, path, { data });
};

//商品排行
export const welcomeGoodsRank = (data?: object,method?:'get') => {
  let path = getnewUrl("/home-statistics-goods",data,method)
  return http.request<ResultTable>(method, path, { data });
};

export const OrderTongji = (data?: object,method?:'get') => {
  let path = getnewUrl("/orders-statistics",data,method)
  return http.request<ResultTable>(method, path, { data });
};

export const setDiyPercent = (data?: object,method?:'post') => {
  let path = getnewUrl("/orders-diy-percent",data,method)
  return http.request<ResultTable>(method, path, { data });
};

export const Statistics = (data?: object,method?:'get') => {
  let path = getnewUrl("/statistics",data,method)
  return http.request<ResultTable>(method, path, { data });
};

export const MaBangStatistics = (data?: object,method?:'get') => {
  let path = getnewUrl("/statistics/mabangorder",data,method)
  return http.request<ResultTable>(method, path, { data });
};

/**
 * 拼装新的方法
 * @param path
 * @param data
 * @param method
 */
function getnewUrl(path,data?: object,method?:'get'){
  if(method ==undefined)method = 'get'
  if(method =='put' || method =='delete'){
    path = path + '/'+data.id
  }else if(method == 'get' && data !==undefined){
    const removeEmpty = obj => Object.keys(obj)
      .filter(key => obj[key] !== undefined && obj[key] !== null && obj[key] !== '')
      .reduce((acc, key) => {
        acc[key] = obj[key];
        return acc;
      }, {});
    data = removeEmpty(data);
    const query = new URLSearchParams(data).toString();
    path = `${path}?${query}`;
  }

  return path;
}
